package com.yanqu.road.server.pb;

import com.yanqu.road.entity.config.beauty.BeautyFavorGain;
import com.yanqu.road.entity.config.beauty.BeautyFavorResult;
import com.yanqu.road.entity.config.beauty.BeautyTrystGain;
import com.yanqu.road.entity.config.beauty.BeautyTrystResult;
import com.yanqu.road.entity.player.*;
import com.yanqu.road.pb.beauty.BeautyPalyProto;
import com.yanqu.road.pb.beauty.BeautyProto;
import com.yanqu.road.utils.property.PropertyHelper;
import com.yanqu.road.utils.string.StringUtils;

import java.util.List;

public class BeautyPb {

    public static BeautyProto.BeautySkillTempMsg.Builder parseBeautySkillTempMsg(UserBeautySkill beautySkill) {
        if(null == beautySkill){
            return null;
        }
        BeautyProto.BeautySkillTempMsg.Builder skillMsg = BeautyProto.BeautySkillTempMsg.newBuilder();
        skillMsg.setSkillPos(beautySkill.getSkillPos());
        skillMsg.setSkillValue(beautySkill.getSkillValue());
        skillMsg.setSkillModifyTimes(beautySkill.getSkillModifyTimes());
        return skillMsg;
    }

    public static BeautyProto.BeautyTempMsg.Builder parseBeautyTempMsg(UserBeauty beauty) {
        if(null == beauty){
            return null;
        }
        BeautyProto.BeautyTempMsg.Builder msg = BeautyProto.BeautyTempMsg.newBuilder();
        msg.setBeautyId(beauty.getBeautyId());
        msg.setIntimacy(beauty.getIntimacy());
        msg.setGlamour(beauty.getGlamour());
        msg.setIdentityLv(beauty.getIdentityLv());
        msg.setChildCount(beauty.getChildCount());
        msg.setLevel(beauty.getLevel());
        msg.setSkill1(beauty.getSkill1());
        msg.setSkill2(beauty.getSkill2());
        msg.setSkillExp(beauty.getSkillExp());
        msg.setIdentitySkillLv(beauty.getIdentitySkillLv());
        msg.setIsShow(beauty.isShow());
        msg.setCreateTime(beauty.getCreateTime());
        msg.setTravelTimes(beauty.getTravelTimes());
        msg.setSkinId(beauty.getSkinId());
        msg.setCurioGlamour(beauty.getCurioGlamour());
        msg.setCurioIntimacy(beauty.getCurioIntimacy());
        msg.setTravelBookIntimacy(beauty.getTravelBookIntimacy());
        msg.setTravelBookGlamour(beauty.getTravelBookGlamour());
        for(UserBeautySkill userBeautySkill : beauty.getSkillMap().values()){
            BeautyProto.BeautySkillTempMsg.Builder skillMsg = parseBeautySkillTempMsg(userBeautySkill);
            if(null != skillMsg) {
                msg.addSkillList(skillMsg);
            }
        }
        msg.setSkinIntimacy(beauty.getSkinIntimacy());
        msg.setSkinGlamour(beauty.getSkinGlamour());
        msg.setQuality(beauty.getQuality());
        msg.setEscortSkill1(beauty.getEscortSkill1());
        msg.setEscortSkill2(beauty.getEscortSkill2());
        msg.setEscortExp(beauty.getEscortExp());
        msg.setSkinSkill1(beauty.getSkinSkill1());
        msg.setSkinSkill2(beauty.getSkinSkill2());
        msg.setPromotionSkill(beauty.getPromotionSkill());
        msg.setPeerlessUpAmount(beauty.getPeerlessUp());
        for (BeautyPeerlessSkillInfo peerlessSkillInfo : beauty.getPeerlessSkillMap().values()) {
            msg.addPeerlessSkill(BeautyProto.BeautyPeerlessSkillTemp.newBuilder().setId(peerlessSkillInfo.getId()).
                    setPatronsId(peerlessSkillInfo.getPatronsId()).
                    setLevel(peerlessSkillInfo.getLevel()).setCd(peerlessSkillInfo.getCd()));
        }
        //自选缘分门客孔位
        for (BeautySelfSelectPatronsPosition patronsPosition : beauty.getSelfSelectPatronsMap().values()) {
            BeautyProto.BeautySelfSelectPatronsTempMsg.Builder tempMsg = buildBeautySelfSelectPatronsTempMsg(patronsPosition);
            msg.addSelfSelectPatronsPosition(tempMsg);
        }
        msg.setGenderSwapMark(beauty.getGenderSwapMark());
        msg.setMusicRoomSkill(PropertyHelper.parsePropertyToString(beauty.getMusicRoomSkill()));
        msg.addAllPromotionSkills(beauty.getPromoteSkillList());
        msg.setTravelBookAlbumSkill(beauty.getAlbumSkillMapStr()); // 旅行册技能
        return msg;
    }

    public static BeautyProto.BeautySimpleTempMsg.Builder parseBeautySimpleTempMsg(UserBeauty beauty) {
        if(null == beauty){
            return null;
        }
        BeautyProto.BeautySimpleTempMsg.Builder msg = BeautyProto.BeautySimpleTempMsg.newBuilder();
        msg.setBeautyId(beauty.getBeautyId());
        msg.setIntimacy(beauty.getIntimacy());
        msg.setGlamour(beauty.getGlamour());
        msg.setSkinId(beauty.getSkinId());
        msg.setSkinIntimacy(beauty.getSkinIntimacy());
        msg.setSkinGlamour(beauty.getSkinGlamour());
        msg.setPeerlessUp(beauty.getPeerlessUp());
        msg.setGenderSwapMark(beauty.getGenderSwapMark());
        msg.setCurioGlamour(beauty.getCurioGlamour());
        msg.setCurioIntimacy(beauty.getCurioIntimacy());
        msg.setTravelBookIntimacy(beauty.getTravelBookIntimacy());
        msg.setTravelBookGlamour(beauty.getTravelBookGlamour());
        //自选缘分门客孔位
        for (BeautySelfSelectPatronsPosition patronsPosition : beauty.getSelfSelectPatronsMap().values()) {
            BeautyProto.BeautySelfSelectPatronsTempMsg.Builder tempMsg = buildBeautySelfSelectPatronsTempMsg(patronsPosition);
            msg.addSelfSelectPatronsPosition(tempMsg);
        }
        return msg;
    }

    public static BeautyProto.BeautyListMsg.Builder parseBeautyListMsg(List<UserBeauty> beautyList){
        BeautyProto.BeautyListMsg.Builder listMsg = BeautyProto.BeautyListMsg.newBuilder();
        if(null != beautyList){
            for(UserBeauty beauty : beautyList){
                BeautyProto.BeautyTempMsg.Builder msg = parseBeautyTempMsg(beauty);
                if(null != msg){
                    listMsg.addBeautyList(msg);
                }
            }
        }
        return listMsg;
    }

    public static BeautyProto.BeautyTrystTempMsg.Builder parseBeautyTrystTempMsg(BeautyTrystGain gain){
        if(null == gain){
            return null;
        }
        BeautyProto.BeautyTrystTempMsg.Builder msg = BeautyProto.BeautyTrystTempMsg.newBuilder();
        msg.setAddExp(gain.getAddExp());
        msg.setBeautyId(gain.getBeautyId());
        if(!StringUtils.isNullOrEmpty(gain.getChildUid())){
            msg.setChildUid(gain.getChildUid());
        }
        msg.setEffectMammonSkill(gain.getEffectMammonSkill());
        return msg;
    }

    public static BeautyProto.BeautyTrystRespMsg.Builder parseBeautyTrystRespMsg(BeautyTrystResult trystResult){
        BeautyProto.BeautyTrystRespMsg.Builder respMsg = BeautyProto.BeautyTrystRespMsg.newBuilder();
        if(null == trystResult) {
            return null;
        }
        if(0 != trystResult.getRet()){
            respMsg.setRet(trystResult.getRet());
            return respMsg;
        }
        respMsg.setRet(trystResult.getRet());
        if (null != trystResult.getResultList()) {
            for (BeautyTrystGain gain : trystResult.getResultList()) {
                BeautyProto.BeautyTrystTempMsg.Builder msg = BeautyPb.parseBeautyTrystTempMsg(gain);
                if(null != msg) {
                    respMsg.addBeautyTrystList(msg);
                }
            }
        }
        return respMsg;
    }


    public static BeautyPalyProto.BeautyFavorTempMsg.Builder parseBeautyFavorTempMsg(BeautyFavorGain gain){
        if(null == gain){
            return null;
        }
        BeautyPalyProto.BeautyFavorTempMsg.Builder msg = BeautyPalyProto.BeautyFavorTempMsg.newBuilder();
        msg.setAddExp(gain.getAddExp());
        msg.setBeautyId(gain.getBeautyId());
        if(!StringUtils.isNullOrEmpty(gain.getChildUid())){
            msg.setChildUid(gain.getChildUid());
        }
        msg.setGuessTimes(gain.getGuessTimes());
        msg.setPoetryTimes(gain.getPoetryTimes());
        return msg;
    }

    public static BeautyPalyProto.BeautyFavorRespMsg.Builder parseBeautyFavorRespMsg(BeautyFavorResult favorResult){
        BeautyPalyProto.BeautyFavorRespMsg.Builder respMsg = BeautyPalyProto.BeautyFavorRespMsg.newBuilder();
        if(null == favorResult) {
            return null;
        }
        if(0 != favorResult.getRet()){
            respMsg.setRet(favorResult.getRet());
            return respMsg;
        }
        respMsg.setRet(favorResult.getRet());
        if (null != favorResult.getResultList()) {
            for (BeautyFavorGain gain : favorResult.getResultList()) {
                BeautyPalyProto.BeautyFavorTempMsg.Builder msg = BeautyPb.parseBeautyFavorTempMsg(gain);
                if(null != msg) {
                    respMsg.addBeautyFavorList(msg);
                }
            }
        }
        return respMsg;
    }

    public static BeautyProto.BeautyVoiceMsg.Builder parseBeautyVoiceMsg(UserBeautyVoice userBeautyVoice){
        BeautyProto.BeautyVoiceMsg.Builder voiceMsgBuilder = BeautyProto.BeautyVoiceMsg.newBuilder();
        if (null == userBeautyVoice){
            return null;
        }
        voiceMsgBuilder.setBeautyId(userBeautyVoice.getBeautyId());
        voiceMsgBuilder.setChooseVoice(userBeautyVoice.getChooseVoice());
        voiceMsgBuilder.addAllRedDotVoiceId(userBeautyVoice.getRedDotVoiceList());
        return voiceMsgBuilder;
    }

    public static BeautyProto.BeautySelfSelectPatronsTempMsg.Builder buildBeautySelfSelectPatronsTempMsg(BeautySelfSelectPatronsPosition patronsPosition) {
        BeautyProto.BeautySelfSelectPatronsTempMsg.Builder tempMsg = BeautyProto.BeautySelfSelectPatronsTempMsg.newBuilder();
        tempMsg.setId(patronsPosition.getId());
        tempMsg.setPatronsId(patronsPosition.getPatronsId());
        tempMsg.setCd(patronsPosition.getCd());
        return tempMsg;
    }
}
